#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int a[N];
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    int mn = *min_element(a, a + n);
    long long sum = 0;
    for (int i = 0; i < n; ++i) sum += a[i] - mn;
    cout << sum << endl;
  }
}
